/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.pub.action;

import static javacommon.util.extjs.Struts2JsonHelper.outXmlJson;

import java.util.List;
import java.util.Map;

import javacommon.util.ResInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.org.rapid_framework.beanutils.BeanUtils;
import cn.org.rapid_framework.web.scope.Flash;

import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.ModelDriven;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.tech15.pub.model.*;
import com.tech15.pub.dao.*;
import com.tech15.pub.service.*;
import com.tech15.pub.vo.query.*;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


public class OfficeItemsCollarAction extends BaseStruts2Action implements Preparable,ModelDriven{
	//默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null; 
	
	//forward paths
	protected static final String LIST_JSP= "/pub/officeItemsCollar_list.jsp";
	protected static final String CREATE_JSP = "/pub/officeItemsCollar_add.jsp";
	protected static final String EDIT_JSP = "/pub/officeItemsCollar_edit.jsp";
	protected static final String SHOW_JSP = "/pub/officeItemsCollar_show.jsp";
	
	protected static final String CREATE_FF_JSP = "/pub/officeItemsCollar_ff.jsp";
	
	protected static final String SEARCH_JSP= "/pub/officeItemsCollar_search.jsp";
	//redirect paths,startWith: !
	protected static final String LIST_ACTION = "!/pub/list.do";
	
	private OfficeItemsCollarManager officeItemsCollarManager;
	private PubDataManager pubDataManager;
	
	private OfficeItemsCollar officeItemsCollar;
	Long id = null;
	private String[] items;

	public void prepare() throws Exception {
		if (isNullOrEmptyString(id)) {
			officeItemsCollar = new OfficeItemsCollar();
		} else {
			officeItemsCollar = (OfficeItemsCollar)officeItemsCollarManager.getById(id);
		}
	}
	
	public void setPubDataManager(PubDataManager manager) {
		this.pubDataManager = manager;
	}
	public void setOfficeItemsCollarManager(OfficeItemsCollarManager manager) {
		this.officeItemsCollarManager = manager;
	}	
	
	public Object getModel() {
		return officeItemsCollar;
	}
	
	public void setId(Long val) {
		this.id = val;
	}

	public void setItems(String[] items) {
		this.items = items;
	}
	
	/** 执行搜索 */
	public String list() {
		OfficeItemsCollarQuery query = newQuery(OfficeItemsCollarQuery.class,DEFAULT_SORT_COLUMNS);
		
		Page page = officeItemsCollarManager.findPage(query);
		savePage(page,query);
		return LIST_JSP;
	}
	
	public String search() {
		OfficeItemsCollarQuery query = newQuery(OfficeItemsCollarQuery.class,DEFAULT_SORT_COLUMNS);
		Page page = officeItemsCollarManager.findPage(query);
		savePage(page,query);
		
		List<PubData> lbList = pubDataManager.searchByPid(new Long(43));
		getRequest().setAttribute("lbList", lbList);
		return SEARCH_JSP;
	}
	
	
	/** 查看对象*/
	public String show() {
		return SHOW_JSP;
	}
	
	/** 进入新增页面*/
	public String create() {
		return CREATE_JSP;
	}
	
	/** 进入新增页面*/
	public String createFf() {
		return CREATE_FF_JSP;
	}
	
	/** 保存新增对象 */
	public void save() {
		Map<String, Object> resInfo = null;
		try{
			officeItemsCollar.setTjsj(DateTools.getCurrentTime());
			boolean m = officeItemsCollarManager.saveOC(officeItemsCollar);
			if(m){
				resInfo = ResInfo.getResInfo("",false, false, 2, this.OPERATE_SUCCESS,"");
			}else{
				resInfo = ResInfo.getResInfo("",false, false, 1, "库存数量不足！","");
			}
		}catch(Exception e){
			e.printStackTrace();
			resInfo = ResInfo.getResInfo("",false, false, 1, this.OPERATE_FAILED,"");
		}
		outXmlJson(resInfo);
	}
	
	/** 保存新增对象 */
	public void saveFf() {
		Map<String, Object> resInfo = null;
		try{
			officeItemsCollarManager.saveFf(officeItemsCollar);
			resInfo = ResInfo.getResInfo("",false, false, 2, this.OPERATE_SUCCESS,"");
		}catch(Exception e){
			e.printStackTrace();
			resInfo = ResInfo.getResInfo("",false, false, 1, this.OPERATE_FAILED,"");
		}
		outXmlJson(resInfo);
	}
	
	/**进入更新页面*/
	public String edit() {
		return EDIT_JSP;
	}
	
	/**保存更新对象*/
	public void update() {
		Map<String, Object> resInfo = null;
		try{
			officeItemsCollarManager.update(this.officeItemsCollar);
			resInfo = ResInfo.getResInfo("",false, false, 2, this.OPERATE_SUCCESS,"");
		}catch(Exception e){
			e.printStackTrace();
			resInfo = ResInfo.getResInfo("",false, false, 1, this.OPERATE_FAILED,"");
		}
		outXmlJson(resInfo);
	}
	
	/**删除对象*/
	public void delete() {
		Map<String, Object> resInfo = null;
		try {
			officeItemsCollarManager.removeById(id);
			resInfo = ResInfo.getResInfo("",false, false, 2, this.OPERATE_SUCCESS,"");
		} catch (Exception e) {
			e.printStackTrace();
			resInfo = ResInfo.getResInfo("",false, false, 1,this.OPERATE_FAILED,"");
		}		
		outXmlJson(resInfo);
	}
	
}
